<?php
namespace Home\Controller;
use Think\Controller;
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');  
// 响应类型  
header('Access-Control-Allow-Methods:*');  
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  

class UploaderController extends Controller {

    public function index() {
        $page="data:image/png;base64,";
        $res['base64']=$this->get_base64_img($page.I("base64"));
        
        
     }

    public function get_base64_img($base64,$path = 'Uploads/'){

        if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64, $result)){
              
            $type = $result[2];
            $new_file = $path.time().".{$type}";
            
            if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64)))){
                return $new_file;
            }else{
                return  false;
            }
        }
 
    }
}
